package algorithm.dichotomy.leetcode;

/**
 * @author: 柒月
 * @date: 2025/5/1 下午5:50
 * @version: 1.0
 */
public class Problem153 {

    // https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/
    public int findMin(int[] nums) {
        int tail = nums.length - 1;
        int left = 0, right = nums.length - 1, mid, ans = -1;
        while (left <= right) {
            mid = left + ((right - left) >> 1);
            if (nums[mid] <= nums[tail]) {
                ans = nums[mid];
                right = mid - 1;
            }else {
                left = mid + 1;
            }
        }
        return ans;
    }
}
